#include "octree_fps.hh"

OctreeFps::OctreeFps (unsigned int size, unsigned int height)
  : Octree (size)
  , map_ (0)
  , height_ (height)
{
  root_ = new NodeFps (size);
}

OctreeFps::OctreeFps (unsigned int size, unsigned int height, Map* map)
  : Octree (size)
  , map_ (map)
  , height_ (height)
{
}

OctreeFps::~OctreeFps ()
{
  delete map_;
}

void
OctreeFps::add_obj (Object* obj)
{
  Vector3d pos;

  pos.val_set (size_ / 2, size_ / 2, height_ / 2);
  root_->add_obj (obj, pos);
}

bool
OctreeFps::delete_obj (Object* obj)
{
  Vector3d pos;

  pos.val_set (size_ / 2, size_ / 2, height_ / 2);
  return (root_->delete_obj (obj, pos));
}

void
OctreeFps::accept (PhysicFunctor* phy)
{
  Vector3d pos;

  pos.val_set (size_ / 2, size_ / 2, height_ / 2);
  root_->accept (phy, pos);
}

void
OctreeFps::accept (DisplayFunctor* disp)
{
  (void) disp;
}

void
OctreeFps::accept (MapFunctor* mf)
{
  unsigned char node[3];

  for (int i = 0; i < map_->height_get (); ++i)
    for (int j = 0; j < map_->width_get (); j += 2)
      {
	node[0] = (*map_) (i, j);
	node[1] = (*map_) (i, j + 1);
	node[2] = '\0';

	(*mf) (node);
      }
}
